
public class TicTacToe2
{

   /**
    * @param args
    */
   public static void main(String[] args)
   {
      //String[] board = {"XXX", "OOX", "XOX"};
      //String[] board = {"OOO", "XXO", "XOX"};
   
       //String[] board = {"XOO", "OXO", "OOX"};
      //String[] board = {"OXX", "XOX", "XXO"};    
      String[] board = {"---", "---", "---"};
      //String[] board = {"XOO", "OXX", "XXO"};
      char x     = 'X';
      char o     = 'O';
      int dash   = 0;
      int X_row_count = 0;
      int O_row_count = 0;
      int X_col_count = 0;
      int O_col_count = 0;
      
      boolean Xwins = false;
      boolean Owins = false;
      
      for(int i=0;i<3;i++)
      {
         for(int j=0;j<3;j++)
         {
            char row_character = board[i].charAt(j);
            
            if(row_character == x)
            {
               X_row_count++;
            }
            else if(o == row_character)
            {
               O_row_count++;
            }
            else if(row_character == '-')
            {
               dash++;
            }
            
       
            char col_character = board[j].charAt(i);

            if(col_character == x)
            {
               X_col_count++;
            }
            else if(col_character == o)
            {
               O_col_count++;
            }
            
         }
         if(X_col_count == 3 || X_row_count == 3)
         {
            Xwins = true;
            
         }
         else if(O_col_count == 3 || O_row_count == 3)
         {
            Owins = true;   
         }
         X_col_count = 0;
         X_row_count = 0;
         O_col_count = 0;
         O_row_count = 0;
                 
      }
      //if no one wins check diagonal
      if(Xwins)
      {
         System.out.println("Xwins");
      }
      else if(Owins)
      {
         System.out.println("Owins");
      }
      else if(!(Xwins && Owins))
      {
         char initial = board[1].charAt(1);
         
         if((initial == board[0].charAt(0) && initial == board[2].charAt(2))
               || (initial == board[0].charAt(2) && initial == board[2].charAt(0)))
         {
               switch(initial)
               {
                  case 'X': System.out.println("Xwins"); break;
                  case 'O': System.out.println("Owins"); break;
                  case '-': System.out.println("NOT OVER"); break;
                  
               }
         }
         else if(dash > 0)
         {
            System.out.println("Not over");
         }
         else
         {
            System.out.println("Tie");
         }    
      }
      else
      {
         System.out.println("TIE");
      }
      

      //System.out.println("X: "+ Xwins + " O:"+ Owins);
   }

}
